package work.dao;


import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import work.po.Book;
import work.po.User;

import java.sql.*;

@Repository
//@Mapper
public class UserDao {

	public String JDBC_URL = "jdbc:mysql://localhost:3306/test_wenxue?serverTimezone=GMT&useSSL=true";
	public String JDBC_USER = "root";
	public String JDBC_PASSWORD = "123456789";

	public User login(String username, String password) throws SQLException {

		User user = new User();

		try (Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD)) {
			try (Statement stmt = conn.createStatement()) {
				try (ResultSet rs = stmt.executeQuery("SELECT * FROM user WHERE username = 2019200100 AND password = 123456")) {
					while (rs.next()) {
                        user.setId(rs.getString(1));
                        user.setUsername(rs.getString(2));
                        user.setPassword(rs.getString(3));
					}
				}
			}
		}
		return user;
	}

	public boolean register(User user) {
		return false;
	}

	//搜索历史记录
//	public void history();
}
